<template>
  <el-dialog :visible="isShow" title="分配角色" @close="closeEvent">
    <el-checkbox-group v-model="roleArr">
      <el-checkbox v-for="item in list" :key="item.id" :label="item.id">
        {{ item.name }}
      </el-checkbox>
    </el-checkbox-group>
    <template #footer>
      <div style="text-align: center">
        <el-button type="primary" @click="submit">提交</el-button>
        <el-button @click="closeEvent">取消</el-button>
      </div>
    </template>
  </el-dialog>
</template>

<script>
import { sysRole } from '@/api/setting'
import { sysUser } from '@/api/user'
import { sysUserAssignRoles } from '@/api/employees'
export default {
  model: {
    prop: 'isShow'
  },
  props: {
    isShow: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      roleArr: [],
      list: [],
      id: ''
    }
  },
  async created() {
    const res = await sysRole({
      page: 1,
      pagesize: 100
    })
    this.list = res.data.rows
  },
  methods: {
    closeEvent() {
      this.$emit('input', false)
      this.roleArr = []
    },
    async getUserInfo(id) {
      this.id = id
      const res = await sysUser(id)
      this.roleArr = res.data.roleIds
    },
    async submit() {
      await sysUserAssignRoles(this.id, this.roleArr)
      this.closeEvent()
    }
  }
}
</script>

<style></style>
